home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter4 / 4.26 / 4.26.cs next >
Text File  |  2004-10-26  |  981b  |  28 lines

  1. /* Assigning values and memory locations to pointers. */
  2. using System;
  3.  
  4. namespace Chapter4 {
  5.     class Class1 {
  6.         static unsafe void Main() {
  7.             int* pointer1, pointer2;
  8.             // Warning, pointer3 is not an actual pointer!
  9.             int variable1 = 1, pointer3;           
  10.     
  11.             // Assigning a pointer to a value
  12.             pointer1 = &variable1; 
  13.             // Pointer to pointer assignments DO NOT require the asterisk.                
  14.             pointer2 = pointer1;   
  15.             // Pointers can also pass values to variables.
  16.             pointer3 = *pointer2;  
  17.                   
  18.             Console.WriteLine("{0}    {1}    {2}    {3}", 
  19.                 variable1, *pointer1, *pointer2, pointer3); 
  20.  
  21.             *pointer1 = 20;  // the value inside that address is now 20.
  22.  
  23.             Console.WriteLine("{0}    {1}    {2}    {3}", 
  24.                 variable1, *pointer1, *pointer2, pointer3);   
  25.         }
  26.     }    
  27. }
  28.